How can I run two commands in one line in Windows CMD?
How can I run two commands in one line in Windows CMD?
629
14-Jul-2023
Updated on 15-Jul-2023
Aryan Kumar
15-Jul-2023Sure, there are two ways to run two commands in one line in Windows CMD:
The ampersand (&) is a special character that can be used to run two commands in one line. When the ampersand is used, CMD will run the first command, and then the second command.
For example, to run the
dircommand and theechocommand in one line, you would use the following command:This will first run the
dircommand, which will list the contents of the current directory. Then, theechocommand will be run, which will display the text "This is the second command."The semicolon (;) is another special character that can be used to run two commands in one line. When the semicolon is used, CMD will run the first command, and then the second command, but only if the first command is successful.
For example, to run the
dircommand and theechocommand in one line, but only if thedircommand is successful, you would use the following command:This will first run the
dircommand. If thedircommand is successful, theechocommand will be run. However, if thedircommand is not successful, theechocommand will not be run.